/*
 * BatchGUI.java
 *
 * Created on March 28, 2007, 10:28 PM
 */
 
package edu.byu.isys413.jjenkins.view;

import edu.byu.isys413.jjenkins.data.*;
import javax.swing.JOptionPane;

/**
 * This form is called to whenever there is a need to batch process various tracks.
 * @author Rick
 */
public class BatchGUI extends javax.swing.JFrame {
    
    private static BatchGUI instance = null;
    
    
    /**
     * gets a single of this class
     */
    public static synchronized BatchGUI getInstance() {
        
        if (instance == null) {
            instance = new BatchGUI();
        }
        return instance;
    }
    /** Creates new form BatchGUI */
    public BatchGUI() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        Sale = new javax.swing.JButton();
        Rental = new javax.swing.JButton();
        Backup = new javax.swing.JButton();
        btnBackup = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        done = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Batch");
        setMinimumSize(new java.awt.Dimension(300, 200));
        jLabel1.setText("Which batch would you like to run?");
        getContentPane().add(jLabel1, java.awt.BorderLayout.NORTH);

        Sale.setText("Order Inventory");
        Sale.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaleActionPerformed(evt);
            }
        });

        jPanel1.add(Sale);

        Rental.setText("Rentals");
        Rental.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RentalActionPerformed(evt);
            }
        });

        jPanel1.add(Rental);

        Backup.setText("Notifications for Order Pickup");
        Backup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BackupActionPerformed(evt);
            }
        });

        jPanel1.add(Backup);

        btnBackup.setText("Backup Notice");
        btnBackup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBackupActionPerformed(evt);
            }
        });

        jPanel1.add(btnBackup);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        done.setText("Done");
        done.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                doneActionPerformed(evt);
            }
        });

        jPanel2.add(done);

        getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnBackupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBackupActionPerformed
 try {
            BackupBatch.GenerateReminder();
        } catch (Exception ex) {
            System.out.println("Can't Generate Reminders");
            ex.printStackTrace();
        }
    }//GEN-LAST:event_btnBackupActionPerformed

    private void doneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_doneActionPerformed
// TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_doneActionPerformed

    private void BackupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BackupActionPerformed
        try {
            PickUpReminderBatch.GenerateReminder();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_BackupActionPerformed

    private void RentalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RentalActionPerformed
// TODO add your handling code here:
        try{
            BatchProcess.getInstance().processMaxDaysOverdue();
        }catch(DataException e){
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, e.toString(), "Error Processing the Max Days Overdue batch process", JOptionPane.ERROR_MESSAGE);
        }
        
        try{
            BatchProcess.getInstance().processMaxTimesRented();
        }catch(DataException e){
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, e.toString(), "Error Processing the Max Times Rented batch process", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_RentalActionPerformed

    private void SaleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaleActionPerformed
        try {
// TODO add your handling code here:
            BatchProcess.getInstance().orderInventory();
        } catch (DataException ex) {
            ex.printStackTrace();
        }
        JOptionPane.showMessageDialog(null, "Making orders for all items that are low in inventory");
        System.out.println("makin orders");
    }//GEN-LAST:event_SaleActionPerformed
     
    /**
     * This method is called fromthe new order form to set the batchGUI visible
     */
    public void populate(){
        this.setVisible(true);
        this.setLocationRelativeTo(null);
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new BatchGUI().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Backup;
    private javax.swing.JButton Rental;
    private javax.swing.JButton Sale;
    private javax.swing.JButton btnBackup;
    private javax.swing.JButton done;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables
    
}
